
INCLUDE_SYS = ../include/sys/
KERNEL = ../kernel/

DIR_OBJ = $(M_DIR_OBJ)/src/api

all: $(INCLUDE_SYS)/api_def.h $(INCLUDE_SYS)/api_index.h $(KERNEL)/kernelApiDef.h $(KERNEL)/kernelApiIndex.h $(M_DIR_BUILD)/docs/kernel_api.html $(M_DIR_BUILD)/docs/kernel_api.txt

$(DIR_OBJ)/.api_def.h: api.def api_def.tcl
	@mkdir -p $(dir $@)
	tclsh api_def.tcl --userland < $< > $@

$(DIR_OBJ)/.kernelApiDef.h: api.def api_def.tcl
	@mkdir -p $(dir $@)
	tclsh api_def.tcl --kernel < $< > $@

$(DIR_OBJ)/.api_index.h: api.index api_index.tcl
	@mkdir -p $(dir $@)
	tclsh api_index.tcl --userland < $< > $@

$(DIR_OBJ)/.kernelApiIndex.h: api.index api_index.tcl
	@mkdir -p $(dir $@)
	tclsh api_index.tcl --kernel < $< > $@


$(INCLUDE_SYS)/api_def.h: $(DIR_OBJ)/.api_def.h
	@if (test -e $@ && diff -qabB $< $@) ; then : ; else cp $< $@ ; fi

$(INCLUDE_SYS)/api_index.h: $(DIR_OBJ)/.api_index.h
	@if (test -e $@ && diff -qabB $< $@) ; then : ; else cp $< $@ ; fi

$(KERNEL)/kernelApiDef.h: $(DIR_OBJ)/.kernelApiDef.h
	@if (test -e $@ && diff -qabB $< $@) ; then : ; else cp $< $@ ; fi

$(KERNEL)/kernelApiIndex.h: $(DIR_OBJ)/.kernelApiIndex.h
	@if (test -e $@ && diff -qabB $< $@) ; then : ; else cp $< $@ ; fi

$(M_DIR_BUILD)/docs/kernel_api.html: api.def $(M_DIR_UTILS)/api2html.sh
	@mkdir -p $(dir $@)
	$(M_DIR_UTILS)/api2html.sh api.def > $@

$(M_DIR_BUILD)/docs/kernel_api.txt: api.def $(M_DIR_UTILS)/api2txt.sh
	@mkdir -p $(dir $@)
	$(M_DIR_UTILS)/api2txt.sh api.def > $@

clean:
	rm -Rf *~ *.o core
